// https://iai.sh.cn/problem/744
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;   //客户的总数量
  cin >> n;
  int ans = 0;    //能卖多少张票，
  int five = 0;   // 5元的零钱的总金额
  int ten = 0;    // 10元的零钱的总金额
  for (int i = 1; i <= n; i++) {
    int k; 
    cin >> k;  //客户的纸币的金额
    if (k == 5) {
      five += 5;
      ans++;
    } else if (k == 10 && five >= 5) {

      five -= 5;
      ten += 10;
      ans++;

    } else if (k == 20 && five >=5 &&  five + ten >= 15) {
      five -= 5;
      if (ten >= 10) {
        ten -= 10;
      } else {
        five -= 10;
      }
      ans++;
    }
  }
  cout << ans;
  return 0;
}